﻿using ProjectFootball.MVC.Models.EntityFramework.Entities;
using System;
using System.Security.Principal;

namespace ProjectFootball.MVC.Areas.CountryArea.Models
{
    public static class _CountryDataModelExtensions
    {
        public static Country CreateNew(this CountryDataModel countryDataModel, IPrincipal user)
        {
            countryDataModel.ApprovalGuid = Guid.NewGuid();

            return countryDataModel.CreateUnapproved(user);
        }

        public static Country CreateUnapproved(this CountryDataModel countryDataModel, IPrincipal user)
        {
            return new Country()
            {
                Pk = Guid.NewGuid(),
                ApprovalGuid = countryDataModel.ApprovalGuid,
                CountryName = countryDataModel.CountryName,
                ActiveFrom = countryDataModel.ActiveFrom,
                ActiveTo = countryDataModel.ActiveTo,
                IsApproved = user.IsApprover(),
                AuditUserId = user.GetUserId(),
                AuditTimestamp = DateTime.Now
            };
        }
    }
}